Test.mockAPI   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
1
import fse from 'fs-extra';
2
import API from './entry';
3
import { tmpFolder } from './constants';
4
import { mockAPI, unMockAPI, startMockApp, stopMockApp } from  './mock';
5
6
export * from './utils';
7
export * from './constants';
8
9
export default class Test {
10
    createAPI(url = 'http://mock/', opts = {}) {
11
        return new API(url, opts);
12
    }
13
14
    async setTmpFolder() {
15
        await fse.ensureDir(tmpFolder);
16
    }
17
18
    async cleanTmpFolder() {
19
        await fse.remove(tmpFolder);
20
    }
21
22
    mockAPI() {
23
        mockAPI();
24
    }
25
26
    unMockAPI() {
27
        unMockAPI();
28
    }
29
30
    async startMockApp() {
31
        this._server = await startMockApp();
32
    }
33
34
    get mockAppUrl() {
35
        const { port } = this._server.address();
36
37
        return `http://localhost:${port}`;
38
    }
39
40
    async stopMockApp() {
41
        await stopMockApp(this._server);
42
    }
43
}
44
45